package com.luoc.base.config.mybatis.controller;

import com.luoc.base.config.mybatis.entity.SysRole;
import com.luoc.base.config.mybatis.service.ISysRoleService;
import com.luoc.base.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: luoc
 * @Date: 2019/7/26 10:02
 */
@RestController
@RequestMapping("/roles")
@Slf4j
public class SysRoleController {

    @Autowired
    private ISysRoleService sysRoleService;

    /**
     * 添加权限
     *
     * @param sysRole
     * @return
     */
    @PostMapping("/add")
    public Result addRoles(@RequestBody SysRole sysRole) {
        return Result.ok(sysRoleService.addRoles(sysRole));
    }

    /**
     * todo @RequiresPermissions 后路径需要完全与权限如今保持一致
     *
     * @param name
     * @return
     */
    @RequiresPermissions("/roles/saveRoleResources")
    @GetMapping("/saveRoleResources")
    public Result saveRoleResources(@RequestParam String name) {
        log.info("roleResourcesName:{}", name);
        return Result.ok("success");
    }
}
